package com.tcd.policy.controller;


import com.tcd.Policy.pojo.WarrantyInfo;
import com.tcd.policy.service.WarrantyInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 保单信息表 前端控制器
 * </p>
 *
 * @author cz
 * @since 2021-05-25
 */
@CrossOrigin
@RestController
@RequestMapping("/warranty-info")
public class WarrantyInfoController {

    @Autowired
    WarrantyInfoService service;

    //查询保单
    @RequestMapping("/getWarrantyInfo")
    public List<WarrantyInfo> getWarrantyInfo(@RequestParam(defaultValue = "1") Integer pageIndex, @RequestParam(defaultValue = "10") Integer pageSize, String warrantyId, String licenseId, String policyholdersName, String insuranceType) {
        List<WarrantyInfo> list = service.getWarrantyInfo(pageIndex,pageSize,warrantyId, licenseId, policyholdersName,insuranceType);
        return list;
    }

    //查询保单总数
    @RequestMapping("/getWarrantyInfoCount")
    public Integer getWarrantyInfoCount(String warrantyId, String licenseId, String policyholdersName){
        Integer count = service.getWarrantyInfoCount(warrantyId,licenseId,policyholdersName);
        return count;
    }

    //查询未审核的保单
    @RequestMapping("/getWarrantyInfoByauditStatus")
    public List<WarrantyInfo> getWarrantyInfoByauditStatus(String warrantyId, String licenseId, String policyholdersName){
        List<WarrantyInfo> list = service.getWarrantyInfoByauditStatus(warrantyId, licenseId, policyholdersName);
        return list;
    }

    //添加交强险
    @RequestMapping("/addWarrantyCompulsory")
    public String addWarrantyCompulsory(@RequestBody WarrantyInfo warrantyInfo) {
        int row = service.addWarrantyCompulsory(warrantyInfo);
        return row > 0 ? "成功" : "失败";
    }

    //添加商业险
    @RequestMapping("/addWarrantyBusiness")
    public String addWarrantyBusiness(@RequestBody WarrantyInfo warrantyInfo) {
        int row = service.addWarrantyBusiness(warrantyInfo);
        return row > 0 ? "成功" : "失败";
    }

    //查询保单商业险
    @RequestMapping("/selectInsureRiskInfo")
    public List<String> selectInsureRiskInfo(String warrantyId){
        List<String> list = service.selectInsureRiskInfo(warrantyId);
        return list;
    }

    //修改保单
    @RequestMapping("/updatePolicyByid")
    public String updatePolicyByid(@RequestBody WarrantyInfo warrantyInfo){
        int row = service.updatePolicyByid(warrantyInfo);
        return row > 0 ? "成功" : "失败";
    }

    //修改交强险保单
    @RequestMapping("/updatePolicyCompulsoryByid")
    public String updatePolicyCompulsoryByid(@RequestBody WarrantyInfo warrantyInfo){
        int row = service.updatePolicyCompulsoryByid(warrantyInfo);
        return row > 0 ? "成功" : "失败";
    }

    //审核保单
    @RequestMapping("/updateAuditStatus")
    public String updateAuditStatus(String auditStatus,String warrantyId){
        int row = service.updateAuditStatus(auditStatus,warrantyId);
        return row > 0 ? "成功" : "失败";
    }

    //根据编号修改出险次数
    @RequestMapping("/updateaccidentsNumById")
    public String updateaccidentsNumById(String[] warrantyId){
        int row = service.updateaccidentsNumById(warrantyId);
        return row > 0 ? "成功" : "失败";
    }
}

